home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / cproto-3.0 / strstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  574 b   |  30 lines

  1. /* $Id: strstr.c 3.3 1992/11/29 04:27:49 cthuang Exp $
  2.  *
  3.  * Simple implementation of the ANSI strstr() function
  4.  */
  5. #include <stdio.h>
  6. #include "config.h"
  7.  
  8. /* Search for a substring within the given string.
  9.  * Return a pointer to the first occurence within the string,
  10.  * or NULL if not found.
  11.  */
  12. char *
  13. strstr (src, key)
  14. char *src, *key;
  15. {
  16.     char *s;
  17.     int keylen;
  18.  
  19.     if ((keylen = strlen(key)) == 0)
  20.     return src;
  21.  
  22.     s = strchr(src, *key);
  23.     while (s != NULL) {
  24.     if (strncmp(s, key, keylen) == 0)
  25.         return s;
  26.     s = strchr(s+1, *key);
  27.     }
  28.     return NULL;
  29. }
  30.